package com.example.dialogprogress;

import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;

public class MainActivity extends AppCompatActivity {

    //定义两个进度条已经一个按钮的变量
    private ProgressBar firstBar  = null;
    private ProgressBar secondBar = null;
    private Button btn1 = null;
    private int i = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        firstBar = (ProgressBar)findViewById(R.id.firstBar);
        secondBar = (ProgressBar)findViewById(R.id.secondBar);
        btn1 = (Button)findViewById(R.id.btn1);
        btn1.setOnClickListener(new ButtonListener());
    }

    class ButtonListener implements View.OnClickListener {

        @Override
        public void onClick(View v)
        {
                if (i == 0) {
                    //将进度条设置可见
                    firstBar.setVisibility(View.VISIBLE);
                    secondBar.setVisibility(View.VISIBLE);
                    //设置进度条的最大值
                    firstBar.setMax(150);
                }
                else if (i < firstBar.getMax()) {
                    //设置主进度条的当前值
                    firstBar.setProgress(i);
                    //设置第二条进度条的当前值
                    firstBar.setSecondaryProgress(i + 10);
                }
                else {
                    firstBar.setVisibility(View.GONE);
                    secondBar.setVisibility(View.GONE);
                }
                i = i + 10;
        }
    }
}
